package panel.clearAll
{
	import assists.ButtonUtils;
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	import inerface.IClearAllPanel;
	
	import main.ClientConstants;
	
	public class ClearAllPanel extends Sprite implements IClearAllPanel
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var onClear:Function;
		private var onCacheClear:Function;
		
		private var titleText:TextField;
		private var clearBtn:ButtonUtils;
		private var clearCacheBtn:ButtonUtils;
		
		public function ClearAllPanel()
		{
		}
		
		public function set clickFunc(func:Function):void
		{
			onClear = func;
		}
		
		public function set clearCache(func:Function):void
		{
			onCacheClear = func;
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			initThis();
		}
		
		private function initThis():void
		{
			titleText = new TextField;
			titleText.wordWrap = true;
			titleText.multiline = true;
			titleText.width = _stage.stageWidth * .8;
			
			this.addChild(titleText);
			titleText.x = _stage.stageWidth * .1;
			titleText.y = _stage.stageHeight * .05 + _stage.stageHeight * ClientConstants.HOME_UP_PER;
			
			TextFieldUtils.setHtmlText(titleText,HtmlText.formatSizeColor("<b>" + "检测服务器端资源是否更新，清理本地旧资源" +"</b>",0xFFFFFF,18));
			
			titleText.width = titleText.textWidth + 5;
			titleText.height = titleText.textHeight + 5;
			
			
			var img:Bitmap = new _loader.uiManager.componentBack as Bitmap;
			img.width = _stage.stageWidth * .6;
			img.height = _stage.stageHeight * .1;
			clearBtn = new ButtonUtils(img,clickAndClear,HtmlText.formatSizeColor("<b>点击清理资源</b>",0x000000,18));
			
			this.addChild(clearBtn);
			clearBtn.x = _stage.stageWidth * .2;
			clearBtn.y = titleText.y + _stage.stageHeight * .05 + titleText.height;
			
			
			var img1:Bitmap = new _loader.uiManager.componentBack as Bitmap;
			img1.width = _stage.stageWidth * .6;
			img1.height = _stage.stageHeight * .1;
			clearCacheBtn = new ButtonUtils(img1,cache,HtmlText.formatSizeColor("<b>点击检查更新</b>",0x000000,18));
			
			this.addChild(clearCacheBtn);
			clearCacheBtn.x = _stage.stageWidth * .2;
			clearCacheBtn.y = clearBtn.y + _stage.stageHeight * .05 + clearBtn.height;
		}
		
		private function clickAndClear():void
		{
			if(onClear is Function){
				onClear();
			}
		}
		
		private function cache():void
		{
			if(onCacheClear is Function){
				onCacheClear();
			}
		}
		
		public function clear():void
		{
			if(_stage){
				_stage = null;
				_loader = null;
				_lang = null;
				_uri = null;
				
				clearBtn.clearThis();
				clearBtn = null;
			}
		}
	}
}